package com.wzy.ldap.event;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

//模板方法 设计模式
@Component
public abstract class AbstractEventMulticaster implements EventMulticaster {
    @Autowired
    private List<WeatherListener> listeners;

    @Override
    public void multicastEvent(WeatherEvent event) {
        doStart();
        listeners.forEach(i -> i.onWeatherEvent(event));
        doEnd();
    }

    @Override
    public void addListener(WeatherListener listener) {
        listeners.add(listener);
    }

    @Override
    public void removeListener(WeatherListener listener) {
        listeners.remove(listener);
    }

    abstract void doStart();

    abstract void doEnd();
}
